package com.iman.manjusri.util;

import java.math.BigInteger;
import java.util.Random;

public class DownAndUploadFilePermissionCodeUtil {

	public static long PermissionCode(String atuhTp ){
		if(util!=null)
		   return util.getPermissionCode(atuhTp);
		else{
			synchronized(DownAndUploadFilePermissionCodeUtil.class){
				if(util == null)
					util = new DownAndUploadFilePermissionCodeUtil();
				
				return util.getPermissionCode(atuhTp);
			}
		}
	}
	
	private static DownAndUploadFilePermissionCodeUtil util = new DownAndUploadFilePermissionCodeUtil();
	private java.util.Random rnd = new Random();

	private BigInteger randomProbableprime() {
		BigInteger big = BigInteger.valueOf(Math.abs(rnd.nextInt()));
		BigInteger probableprime = 	big.nextProbablePrime();
		return probableprime.nextProbablePrime();
	}
	
	private   long getPermissionCode(String atuhTp ){
		Permission perm = 	Enum.valueOf(Permission.class, atuhTp);
		BigInteger  rnd  = this.randomProbableprime().setBit(perm.permissionVal);
		return rnd.longValue();
	}
	
	public static enum Permission {
		USER_UPLOAD_ADDRESS_IMAGE(29), ADMIN_UPDALOAD_FILE(11), CUSTOMER_DOWNLOAD_KNOWLEDGE(33);
		public int permissionVal = 0;
		Permission(int permission) {
			this.permissionVal = permission;
		}
	}
	
	public static void  main (String...strings ){
		long p = 	new DownAndUploadFilePermissionCodeUtil().getPermissionCode("ADMIN_UPDALOAD_FILE");
		System.out.println(p);
	}
	
	@Override
	public void finalize(){
		
		try {
			super.finalize();
			DownAndUploadFilePermissionCodeUtil.util = null;
		} catch (Throwable e) {
		}
	}
}

